#ifndef _DRV_SERIAL_STM32F411X_H_
#define _DRV_SERIAL_STM32F411X_H_

#include "stm32f4xx.h"
#include "stm32f4xx_ll_rcc.h"
#include "stm32f4xx_ll_bus.h"
#include "stm32f4xx_ll_spi.h"
#include "stm32f4xx_ll_usart.h"
#include "stm32f4xx_ll_gpio.h"
#include "hal_device.h"
#include "hal_serial.h"

#include "drv_gpio_stm32f4xx.h"

#define STM32F4XX_UART1_TXD_PIN1  {LL_GPIO_PIN_9, GPIOA,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOA}
#define STM32F4XX_UART1_RXD_PIN1  {LL_GPIO_PIN_10,GPIOA,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOA}

#define STM32F4XX_UART2_TXD_PIN1  {LL_GPIO_PIN_5, GPIOD,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOD}
#define STM32F4XX_UART2_RXD_PIN1  {LL_GPIO_PIN_6, GPIOD,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOD}

#define STM32F4XX_UART2_TXD_PIN2  {LL_GPIO_PIN_2, GPIOA,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOA}
#define STM32F4XX_UART2_RXD_PIN2  {LL_GPIO_PIN_3, GPIOA,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOA}

#define STM32F4XX_UART3_TXD_PIN1  {LL_GPIO_PIN_8, GPIOD,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOD}
#define STM32F4XX_UART3_RXD_PIN1  {LL_GPIO_PIN_9, GPIOD,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOD}

#define STM32F4XX_UART3_TXD_PIN2  {LL_GPIO_PIN_10,GPIOB,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOB}
#define STM32F4XX_UART3_RXD_PIN2  {LL_GPIO_PIN_11,GPIOB,LL_GPIO_AF_7,LL_AHB1_GRP1_PERIPH_GPIOB}

#define STM32F4XX_UART4_TXD_PIN1  {LL_GPIO_PIN_0, GPIOA,LL_GPIO_AF_8,LL_AHB1_GRP1_PERIPH_GPIOA}
#define STM32F4XX_UART4_RXD_PIN1  {LL_GPIO_PIN_1, GPIOA,LL_GPIO_AF_8,LL_AHB1_GRP1_PERIPH_GPIOA}

#define STM32F4XX_UART5_TXD_PIN1  {LL_GPIO_PIN_12,GPIOC,LL_GPIO_AF_8,LL_AHB1_GRP1_PERIPH_GPIOC}
#define STM32F4XX_UART5_RXD_PIN1  {LL_GPIO_PIN_2, GPIOD,LL_GPIO_AF_8,LL_AHB1_GRP1_PERIPH_GPIOD}

#define STM32F4XX_UART6_TXD_PIN1  {LL_GPIO_PIN_11,GPIOA,LL_GPIO_AF_8,LL_AHB1_GRP1_PERIPH_GPIOA}
#define STM32F4XX_UART6_RXD_PIN1  {LL_GPIO_PIN_12,GPIOA,LL_GPIO_AF_8,LL_AHB1_GRP1_PERIPH_GPIOA}

#define STM32F4XX_UART1_DATA      {USART1, LL_APB2_GRP1_PERIPH_USART1, LL_APB2_GRP1_EnableClock, NULL, NULL, 5,  0, 0x00, USART1_IRQn}
#define STM32F4XX_UART2_DATA      {USART2, LL_APB1_GRP1_PERIPH_USART2, LL_APB1_GRP1_EnableClock, NULL, NULL, 6,  0, 0x00, USART2_IRQn}
#define STM32F4XX_UART3_DATA      {USART3, LL_APB1_GRP1_PERIPH_USART3, LL_APB1_GRP1_EnableClock, NULL, NULL, 7,  0, 0x00, USART3_IRQn}
#define STM32F4XX_UART4_DATA      {UART4,  LL_APB1_GRP1_PERIPH_UART4,  LL_APB1_GRP1_EnableClock, NULL, NULL, 8,  0, 0x00, UART4_IRQn}
#define STM32F4XX_UART5_DATA      {UART5,  LL_APB1_GRP1_PERIPH_UART5,  LL_APB1_GRP1_EnableClock, NULL, NULL, 9,  0, 0x00, UART5_IRQn}
#define STM32F4XX_UART6_DATA      {USART6, LL_APB2_GRP1_PERIPH_USART6, LL_APB2_GRP1_EnableClock, NULL, NULL, 10, 0, 0x00, USART6_IRQn}


struct stm32f411x_uart_data{
    USART_TypeDef               *USARTx;
    uint32_t                     clock;
    void                       (*enable_clock)(uint32_t Periphs);
    struct stm32f4xx_gpio_s 	*txd;
	struct stm32f4xx_gpio_s 	*rxd;
    uint8_t                     irq_pre_pri;
	uint8_t                     irq_sub_pri;   
    uint32_t                    new_data_from_int;
    IRQn_Type                   irq;	
};

void stm32f4_serial_register(char *name,struct hal_serial_s *serial,struct stm32f411x_uart_data *uart);

#endif
